﻿@{
    ViewBag.Title = "Body";
    string query = "&id=" + Request.QueryString["id"] + "&appid=" + Request.QueryString["appid"]
        + "&parentid=" + Request.QueryString["parentid"] + "&type=" + Request.QueryString["type"];
}
@model YJ.Data.Model.Organize
<script type="text/javascript">
    var win = new RoadUI.Window();
    var validate = new RoadUI.Validate();
</script>
<form method="post">
@Html.AntiForgeryToken()
<br />
<table cellpadding="0" cellspacing="1" border="0" width="95%" class="formtable">
    <tr>
        <th style="width:80px;">名称：</th>
        <td><input type="text" id="Name" name="Name" class="mytext" validate="empty,minmax" value="@Model.Name" max="100" style="width:75%" /></td>
    </tr>
    <tr>
        <th style="width:80px;">类型：</th>
        <td>@Html.Raw(ViewBag.TypeRadios)</td>
    </tr>
    <tr>
        <th style="width:80px;">状态：</th>
        <td>@Html.Raw(ViewBag.StatusRadios)</td>
    </tr>
    @if("1"!=Request.QueryString["type"]){
    <tr>
        <th style="width:100px;">分管领导：</th>
        <td><input type="text" class="mymember" value="@Model.ChargeLeader" unit="0" dept="0" station="0" user="1" group="0" id="ChargeLeader" name="ChargeLeader" /></td>
    </tr>
    <tr>
        <th style="width:80px;">部门/岗位领导：</th>
        <td><input type="text" class="mymember" value="@Model.Leader" unit="0" dept="0" station="0" user="1" group="0" id="Leader" name="Leader" /></td>
    </tr>
    }
    <tr>
        <th style="width:80px;">备注：</th>
        <td><textarea id="Note" name="Note" class="mytext" style="width:90%; height:50px;">@Model.Note</textarea></td>
    </tr>

    <tr id="deptmove_tr" style="display:none;">
        <th style="width:80px;">移动到：</th>
        <td>
            <table cellpadding="0" cellspacing="1" border="0">
                <tr>
                    <td><input type="text" style="width:220px;" class="mymember" id="deptmove" name="deptmove" more="false" user="false" station="true" dept="true" unit="true"/></td>
                    <td><input type="submit" class="mybutton" onclick="return deptmove3();" name="Move1" value="确定移动" /></td>
                </tr>
            </table>
        </td>
    </tr>

</table>
<div style="width:95%; margin:10px auto 10px auto; text-align:center;">
    <style type="text/css">
        .upload {
            padding: 4px 5px 5px;
            color: #fff !important;
            text-decoration: none !important;
            margin-right: 2px;
            position: relative;
            background: #3499f0;
            border: 1px solid #0e66c9;
        }

        .change {
            position: absolute;
            overflow: hidden;
            right: 0;
            top: 0;
            opacity: 0;
        }
    </style>
    <input type="button" class="mybutton" value="设置菜单" onclick="setMenu();" />
    <input type="button" class="mybutton" onclick="window.location='BodyAdd'+'@Html.Raw(Request.Url.Query)';" value="添加单位/部门/岗位" id="addChild" />
    <input type="button" class="mybutton" onclick="window.location='UserAdd'+'@Html.Raw(Request.Url.Query)';" value="添加人员" id="addUser" />
    <input type="button" class="mybutton" value="移动" id="move" name="move" onclick="deptmove2();" />
    <input type="button" class="mybutton" value="排序" id="sort" onclick="sort1();" />
    <a href="javascript:;" class="upload" id="upload">
        导入<input class="change" style="width:70px;" multiple="multiple" value="" id="upFile" name="upFile" onchange="FileUploads(1);" type="file">
    </a>
    <input type="submit" class="mybutton" onclick="return validate.validateForm(document.forms[0]);" name="Save" value="保存" />
    <input type="submit" class="mybutton" name="Delete" onclick="return confirm('您真的要删除该机构及其下级机构吗?');" value="删除" />
    @if (YJ.Platform.WeiXin.Config.IsUse && Model.ID == new YJ.Platform.Organize().GetRoot().ID)
    {
        <input type="submit" class="mybutton" name="ToWeiXin" onclick="return confirm('真的要将整个组织机构同步到微信吗?');" value="同步到微信" />
    }
</div>
</form>
<script src="~/Scripts/ajaxfileupload.js"></script>
<script type="text/javascript">
    var showType = '';
    $(function(){
        @Html.Raw(ViewBag.Script)
    });
    function del()
    {
        return confirm('真的要删除吗?');
    }
    function deptmove3()
    {
        if ($.trim($("#deptmove").val()) == "")
        {
            alert("请选择要移动到的机构!");
            return false;
        }
        else if ($.trim($("#deptmove").val()) == '@Request.QueryString["id"]')
        {
            alert("不能将机构移动到自己!");
            return false;
        }
        return true;
    }
    function deptmove2()
    {
        $('#deptmove_tr').toggle();
    }

    function sort1()
    {
        window.location = 'Sort?1=1' + '@Html.Raw(query)';
    }
    function setMenu()
    {
        var url="SetMenu?prev=@(("Body"+Request.Url.Query).UrlEncode())@Html.Raw(query)";
        //top.mainDialog.open({url: url,width:900,height:550,title:"设置菜单",opener:parent});
        window.location=url;
        return false;
    }
    function FileUploads(type) {
        var OrganizeID='@Model.ID';
        try {
            $.ajaxFileUpload({
                url: '/Api/FileUpload/upLoad?type=' + type + '&OrganizeID=' + OrganizeID,
                contentType: "application/json",
                type: 'Post',
                //一般设置为false
                secureuri: false,
                //文件上传空间的id属性  <input type="file" id="file" name="file" />
                fileElementId: 'upFile',
                dataType: 'text',
                async: true,
                //返回值类型 一般设置为json
                success: function (data) //服务器成功响应处理函数
                {
                    data = data.replace("<pre>", "");
                    data = data.replace("</pre>", "");
                    alert(data);
                    parent.frames[0].reLoad(OrganizeID);
                    window.location = window.location;
                }
                , error: function (request, status, error) {
                    alert("发生错误");
                    alert(request.responseText);
                }
            });
        } catch (e) {
            alert(e.message);
        }
    }
</script>
